package dao;

import java.sql.ResultSet;

import modal.UserModal;

public class UsersDAO extends BaseDAO{
// no need to use user id since it is auto increment 
	public void addUser(String email, String pass) throws Exception {
        String query = "INSERT INTO `users` (`Email`, `Pass`) VALUES ( '" + email + "',"   +  "'" + pass + "'"  +")";
        execQuery(query);
    }

	public UserModal getUserwithEmail(String email) throws Exception {
		
		String query = "SELECT * FROM `users` WHERE email = '"+email+"'";
		ResultSet rs =execQuery(query);
		UserModal user=null;
		if(rs.next()){
		user = new UserModal(rs.getInt("UserId"),rs.getString("Pass"),rs.getString("Email"));
		} 
		return user; 
	}

	public UserModal getUserwithId(int ownerId) throws Exception {
		String query = "SELECT * FROM `users` WHERE UserID = "+ownerId+"";
		ResultSet rs =execQuery(query);
		UserModal user=null;
		if(rs.next()){
		user = new UserModal(rs.getInt("UserId"),rs.getString("Pass"),rs.getString("Email"));
		} 
		System.out.println(rs.getString("Email"));
		return user; 
	}
}
  